/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import agh.rozproszony.model.Reservation;
import agh.rozproszony.model.User;
import agh.rozproszony.reservations.ReservationsServer;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Marcin_PC
 */
public class ReservationTable extends AbstractTableModel {

    private List<ReservationRowWrapper> rows;
    private final static Object[] columnNames = {"Pokój", "Rezerwujący", "Data Rezerwacji", "Od", "Do"};
    private final static int ROOM_IDX = 0;
    private final static int RESERVATIONO_OWNER_IDX = 1;
    private final static int DATA_IDX = 2;
    private final static int FROM_HOUR_IDX = 3;
    private final static int TO_HOUR_IDX = 4;
    //private final static int INVITED_IDX = 5;

    public ReservationTable() {
        this.rows = new ArrayList<ReservationRowWrapper>();
    }

    @Override
    public int getRowCount() {
        if (rows == null) {
            return 0;
        }
        return rows.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        if (rows == null) {
            return null;
        }
        ReservationRowWrapper row = (ReservationRowWrapper) rows.get(rowIndex);
        switch (columnIndex) {
            case ROOM_IDX:
                return row.getRoom();
            case RESERVATIONO_OWNER_IDX:
                return row.getOwner();
            case DATA_IDX:
                return row.getDate();
            case FROM_HOUR_IDX:
                return row.getTimeFrom();
            case TO_HOUR_IDX:
                return row.getTimeTo();
            default:
                return row;
        }
    }

    @Override
    public String getColumnName(int column) {
        return columnNames[column].toString();
    }

    public void setModelData(List<Reservation> reservations, ReservationsServer server) {
        rows.clear();
        for (Reservation res : reservations) {
            ReservationRowWrapper row = new ReservationRowWrapper(res, server);

            rows.add(row);
        }
    }
}
